package ua.kharkov.knure.mikhaylov.st4.db.entities;

import java.io.Serializable;
import java.util.Random;

/**
 * Card db entity
 * 
 * @author Saint
 *
 */
public class Card implements Serializable {

	private static final long serialVersionUID = 486527088175637350L;

	private long id;
	private int number;
	private int securityCode;
	private Account account;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public int getSecurityCode() {
		return securityCode;
	}

	public void setSecurityCode(int securityCode) {
		this.securityCode = securityCode;
	}

	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	/**
	 * Here must be some card number generation algorhytm. Maybe next time it
	 * will really be here
	 */
	public void generateNumber() {
		Random r = new Random();
		number = (int) ((account.getId() + r.nextInt(1000)) * 
				(213 + r.nextInt(100)) + 7 + r.nextInt(100000));
	}

	public void generateSecCode() {
		Random r = new Random();
		securityCode = r.nextInt(1000);
	}
	
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Card))
			return false;
		Card other = (Card) obj;
		return (id == other.id && number == other.number
				&& securityCode == other.securityCode
				&& account.equals(other.account));
	}
}
